<script type="text/javascript">
$(document).ready(function(){
	$(".buy a").click(function(){
		$.ajax({
			url: "<?php echo $this->url(array("action" => "add"), "cart"); ?>",
			data: "pid="+ $(this).attr("href"),
			type: "POST",
			dataType: "html",
			success: function(data){
				if(confirm("Sản phẩm đã được cho vào giỏ hàng.\nBạn có muốn xem giỏ hàng của bạn không?"))
						location.href = "<?php echo $this->url(array(), "cart");?>"	;
			}
		});
		return false;
	});
	$("#frmSearch").submit(function(){
		var keyword = $("#keyword").attr("value");
		if( keyword == '' || keyword == "Tìm sản phẩm..."){
			alert("Bạn cần nhập từ khóa tìm kiếm!");
			return false;
		}
	});
});
</script>
<div id="main_content">
        	<div id="top">
            	<div id="contact_banner">
            	<?php Helper_HtmlRender::renderImageOrFlash($this->banners[2]->image, 723, 76, 'Thiết bị văn phòng Cường Phú')?>
            	</div>
            </div><!-- end top left_main_content block-->
        	<div id="left_main_content"><!--start left main content-->
            	<div class="title_box" id="filter_box">
                	<div class="text_title_box" >Lọc sản phẩm</div>
                </div>
               
                <div class="filter_box">

                	<div class="title_filter_box">Hãng sản xuất</div>
                    <ul class="filter_option">
                    	<?php
                    	if(isset($this->currentMan)){
                    		echo "<li><span style='float:left;'>".$this->currentMan->name." (".$this->currentManPostNumber.")</span><a href='".$this->currentMan->id."' class='manfilter btnDrop'><img src='".PUBLIC_URL."/skins/default/images/b_drop.png' alt='Xóa'/></a></li>";
                    	}else{
                    		foreach ($this->arrManFilters as $manFilter){
                    	?>
                    	<li>
                    		<a class ="ofilter manfilter" href="<?php echo $manFilter["id"];?>"><?php echo $manFilter["name"];?></a>
                    		<span class="count_filter"> (<?php echo $manFilter["productNumber"]?>)</span>
                    	</li>
                    	
                    	<?php 
                    		}
                    	} 
                    	?>
                    	
                       
                    </ul>
                </div><!--end filter box-->
                <?php
                foreach ($this->arrFilterValueSets as $filterName => $filterValues){
                ?>
                <div class="filter_box">
                	<div class="title_filter_box"><?php echo $filterName;?></div>
                    <ul class="filter_option">
                <?php
                	if(is_array($filterValues[0])){ 
                		foreach ($filterValues as $filterValue){
                ?>
                		<li><a class="filtervalue ofilter" href="<?php echo $filterValue["id"]?>"><?php echo $filterValue["text"];?></a><span class="count_filter">(<?php echo $filterValue["numberProduct"]?>)</span></li>
                <?php
                		}
                	}else{
                
                		echo "<li><span style='float:left;'>".$filterValues["text"]." (".$filterValues["numberProduct"].")</span><a href='".$filterValues["id"]."'class='filtervalue btnDrop'><img src='".PUBLIC_URL."/skins/default/images/b_drop.png' alt='Xóa'/></a></li>";
                
                	}
                ?>
                	</ul>
                </div><!--end filter box-->
                <?php 
                } 
                ?>

            </div><!-- end left_main_content block -->
            <div id="right_main_content"><!--start right main content-->

            	<div id="title_right_main_content">
                	<div id="breadcrumb">
                		<a href="<?php echo $this->url(array(), 'default');?>">Trang chủ</a> 
                		
                		<?php
                		if($this->pCategory->level == 2){
                			$parentCategory = $this->pCategory->findParentRow("Model_PCategory");
                			echo "&gt;&gt;<a href='".$this->url(array("cat_id" => $parentCategory->id, "cat_name" => Helper_Converter::stringToSlug($parentCategory->name), "page" => ""),"pcategory")."'>".$parentCategory->name."</a>";
                		}
                		echo "&gt;&gt;<a href='".$this->url(array("cat_id" => $this->pCategory->id, "cat_name" => Helper_Converter::stringToSlug($this->pCategory->name), "page"=> ""),"pcategory")."'>".$this->pCategory->name."</a>";
                		
                		?>
                	</div>
                    <select name="select_sort" id="select_sort_box">
                    	<option value="">--Sắp xếp theo giá--</option> 	
                    	<option value="desc">Giá giảm dần</option>
                        <option value="asc">Giá tăng dần</option>                       
                    </select>
                </div>
                <?php if(count($this->arrProducts) > 0){?>
                <div id="products">
                	<?php
                	foreach($this->arrProducts as $product){
                		$arrImages = explode('@', $product["image"]);//để tách chuối ra thàng mảng mình sẽ lấy thằng ảnh đầu tiên
                	?>
                	<div class="product">
                		<div class="image_product">
							<a href="<?php echo $this->url(array("slug" => $product["slug"]),"product");?>">
								<?php 
		                		
		                		if(extension_loaded("gd") && function_exists("exec") ){ 
		                		?>
									<img src="<?php echo PUBLIC_URL.'/plugins/phpThumb/phpThumb.php?src='.$arrImages[0].'&amp;w=134&amp;h=99'?>" /> 	
								<?php }else{?>
									<img src="<?php echo $arrImages[0]?>" width="134px" height="99px" />
								<?php }?>
								</a>
						</div>
	                    <div class="model_product"><a href="<?php echo $this->url(array("slug" => $product["slug"]),"product");?>"><?php echo $product["model"];?></a></div>
	                    <div class="decription_product"><?php //echo $product["description"];?></div>
	                    <div class="price_product"><?php echo number_format($product["price"]);?> VND</div>
	                    <div class="action">
	                    	<div class="buy"><a href="<?php echo $product["id"]?>">Mua</a></div>
	                        <div class="show_detail"><a href="<?php echo $this->url(array("slug" => $product["slug"]),"product");?>">Chi tiết</a></div>
	
	                    </div>
	              	</div><!--end product block -->
                	<?php 
                	}
                	?>
	               	<div id="clear"></div>
                </div>
                
            	<?php
            	echo $this->paginationControl($this->arrProducts,
                                    'Sliding',
                                    'pcategory/pagination.phtml', array('pCategory' => $this->pCategory)); 
                }else{?>
                <div id="error">Không có sản phẩm nào phù hợp</div>
                <?php }?>
            </div><!-- end right_main_content block -->
           
        </div><!-- end main_content block -->
        <div id="right"><!--start right block-->
        	<div id="search_box">
        		<form id="frmSearch" action="<?php echo $this->url(array(), "search");?>" method="get">
        			<input type="text" onclick="value='';"  id="keyword" name="keyword" value="Tìm sản phẩm..."/>
                	<input type="submit" id="submit_button" value="Tìm kiếm" />
        		</form>
            	
            </div><!-- end search_block-->
            <div id="cart_box">
            	<div id="title_cart"><a href="<?php echo $this->url(array(),"cart");?>">Giỏ hàng của bạn</a></div>
                <div class="cart_info">
                	<span class="left_info">Số sản phẩm:&nbsp; </span>
                    <span class="right_info"><?php echo $this->totalCartProduct;?></span>
                </div>
                <div class="cart_info">
                	<span class="left_info">Tổng tiền:&nbsp;</span>
                    <span class="right_info"><?php echo number_format($this->totalCartPrice);?> VND</span>
                </div>
            </div> <!-- end cart_block -->
            <?php
            //lấy dữ liệu để điền vào 2 box hỗ trợ trực tuyến
            $arrSalers = array();
            $arrTechnicians = array(); 
            foreach ($this->supporters as $supporter){
            	if($supporter->type == 0){
            		$arrSalers[] = $supporter;
            	}else{
            		$arrTechnicians[] = $supporter;
            	}
            }
            
                  
            ?>
            <div class="right_box">
            	<div class="title_box">
                	<div class="text_title_box">Bán hàng trực tuyến</div>
                    <div class="phone_title_box">(04) 35 68 36 99</div>
                </div>
                <?php $count_business =count($arrSalers);
               	if($count_business>0){
               	for( $i=0;$i<$count_business;$i++){?>
               	 <div class="supporter">
                	<div class="info_supporter">
                    	<div class="name_supporter">
                        	<a href="ymsgr:SendIM?<?php echo $arrSalers[$i]->yahoo_account;?>"  title="Contact to supporter!">
         						<?php echo $arrSalers[$i]->name;?>
                            </a>
                            </div>
                       	<div class="phone_supporter"><?php echo $arrSalers[$i]->phone;?></div>
                        <div class="email_supporter"><?php echo $arrSalers[$i]->email;?></div>
                        
                    </div>
                    <a href="ymsgr:SendIM?<?php echo $arrSalers[$i]->yahoo_account;?>"  title="Contact to supporter!">
                            <img  alt="" src="http://opi.yahoo.com/online?u=<?php echo $arrSalers[$i]->yahoo_account;?>&m=g&t=1" border="0"/>
                        </a>
                    <?php if($i+2 <= $count_business){?><div class="line"></div><?php } ?>
                </div>
               <?php }
               	 } ?>
                
               
            </div><!-- end right_box-->           
            <div class="right_box">
            	<div class="title_box">
                	<div class="text_title_box">Hỗ trợ kỹ thuật</div>
                    <div class="phone_title_box">(04) 66 84 87 86</div>
                </div>
                <?php $count_technical =count($arrTechnicians);
               	if($count_technical>0){
               	for( $i=0;$i<$count_technical;$i++){?>
               	 <div class="supporter">
                	<div class="info_supporter">
                    	<div class="name_supporter">
                        	<a href="ymsgr:SendIM?<?php echo $arrTechnicians[$i]->yahoo_account;?>"  title="Contact to supporter!">
         						<?php echo $arrTechnicians[$i]->name;?>
                            </a>
                            </div>
                        <div class="phone_supporter"><?php echo $arrTechnicians[$i]->phone;?></div>
                        <div class="email_supporter"><?php echo $arrTechnicians[$i]->email;?></div>
                        
                    </div>
                    <a href="ymsgr:SendIM?<?php echo $arrTechnicians[$i]->yahoo_account;?>"  title="Contact to supporter!">
                            <img  alt="" src="http://opi.yahoo.com/online?u=<?php echo $arrTechnicians[$i]->yahoo_account;?>&m=g&t=1" border="0"/>
                        </a>
                    <?php if($i+2 <= $count_technical){?><div class="line"></div><?php } ?>
                </div>
               <?php }
               	 } ?>
            </div><!-- end right_box-->
            <?php
            echo $this->partial("include/tags.phtml", array("tags" => $this->tags));
            ?>
                                                 
        </div><!-- end right block -->
        <div id="clear"></div>
